#ifndef _FTPSTREAMFACTORY_HPP_
#define _FTPSTREAMFACTORY_HPP_

#include "jhdefs.hpp"
#include "net/URI.hpp"
#include "net/URIStreamFactory.hpp"

#include <string>

NET_NAMESPACE_BEGIN

class CFTPPasswordProvider
{
public:
	virtual std::string password(const std::string& username, const std::string& host) = 0;

protected:
	CFTPPasswordProvider();
	virtual ~CFTPPasswordProvider();
};


class CFTPStreamFactory : public CURIStreamFactory
{
public:
	CFTPStreamFactory();
	~CFTPStreamFactory();

	std::istream* open(const CURI& uri);
	
	static void setAnonymousPassword(const std::string& password);
	static const std::string& getAnonymousPassword();
	static void setPasswordProvider(CFTPPasswordProvider* pProvider);
	static CFTPPasswordProvider* getPasswordProvider();

	static void registerFactory();
	static void unregisterFactory();

protected:
	static void splitUserInfo(const std::string& userInfo, std::string& username, std::string& password);
	static void getUserInfo(const CURI& uri, std::string& username, std::string& password);
	static void getPathAndType(const CURI& uri, std::string& path, char& type);

private:
	static std::string			 m_anonymousPassword;
	static CFTPPasswordProvider* m_pPasswordProvider;
};


NET_NAMESPACE_END

#endif
